<?php

// 本类由系统自动生成，仅供测试用途
class GroupAction extends CommonAction {

    public function index() {

        $group = M('group');
        $rawGroups = $group->select();

        $this->assign('rawGroups', $rawGroups);
        $this->assign('pagetitle', 'Splio | Group Management');
        $this->assign('groupManagementActive', 'active');
        
        $this->display();
    }


    public function doadd() {
        $formData = $_POST;

        $formData['time'] = time();

        $group = M('group');

        $formData['gid'] = $group -> add($formData);

        echo json_encode($formData);
    }


    public function show() {

    	$group = M('group');
    	$rawGroups = $group->where("enable=1")->select();

    	$this->assign('rawGroups', $rawGroups);
    	$this->assign('pagetitle', 'Splio | Group');
    	$this->assign('ispShowActive', 'active');
    	
    	$this->display();
    }


    public function status() {

        $data = $_POST;
        $aid = array_shift($data);

        $group = M('group');

        $rawGroups = $group->where("aid=$aid")->save($data);

        echo json_encode($rawGroups);
    }


    public function doupdate() {

        $formData = $_POST;

        $aid = array_shift($formData);
        if(isset($formData['pwd']) && $formData['pwd'])
        {
            $formData['pwd'] = encrypt($formData['pwd']);
        }
        
        $group = M('group');

        $result = $group -> where("aid=$aid") -> save($formData);

        echo $result;
    }


    public function doresume() {

     $formData = $_POST;

        $id = array_shift($formData);

        $formData['enable'] = 1;

        $group = M('group');

        $result = $group -> where("id=$id") -> save($formData);

        echo $result;   
    }


    public function getAll() {
        $result = array();

        $group = M('group');
        $rawGroups = $group->select();

        foreach ($rawGroups as $rawGroup) {
            $result[$rawGroup['id']] = $rawGroup;
        }

        return $result;
    }

}